const TRANS_TYPE = {
    'Harlee': LangLocal.word58,
    'BNW': LangLocal.word49,
    'Ducadi': LangLocal.word50,
    'Yanaha': LangLocal.word51,
    'Honduh': LangLocal.word52,
}
const TRANS_INFO = {
    'Harlee': LangLocal.word53,
    'BeeMW': LangLocal.word54,
    'Ducatee': LangLocal.word55,
    'Yamahuh': LangLocal.word56,
    'Honduh': LangLocal.word57,
}

cc.Class({
    extends: cc.Component,

    properties: {
        motorName: cc.Label,
        motorDesc: cc.Label,
        motorOdds: cc.Label,
        motorArma: dragonBones.ArmatureDisplay,
        motorState: cc.ProgressBar,
        motorEnergy: cc.Graphics,

        lb_champion: cc.Label,
        lb_attribute1: cc.Label,
        lb_attribute2: cc.Label,
        lb_attribute3: cc.Label,
        lb_attribute4: cc.Label,
        lb_attribute5: cc.Label,
        lb_sex: cc.Label,
    },

    onLoad() {
        var rdos = this.node.find('rdos').children;
        this.energys = [];
        for (var i = 0; i < rdos.length; ++i) {
            rdos[i].on('toggle', this.onToggle, this);
            this.energys.push(GLOBAL.getMotorEnergy(i));
        };
        this.rdos = rdos;
        this.updateInfo(0);
        this.initWords();
    },

    initWords: function(){
        this.lb_champion.string = LangLocal.word33;
        this.lb_attribute1.string = LangLocal.word34;
        this.lb_attribute2.string = LangLocal.word35;
        this.lb_attribute3.string = LangLocal.word36;
        this.lb_attribute4.string = LangLocal.word37;
        this.lb_attribute5.string = LangLocal.word38;
        this.lb_sex.string = LangLocal.word39;
    },

    switchInfo(order) {
        this.rdos[order].emit('touchstart');
        this.rdos[order].emit('touchend');
    },

    onToggle(evt) {
        this.updateInfo(this.rdos.indexOf(evt.target));
    },

    updateInfo(order) {
        var roles = ['红', '绿', '蓝', '紫', '黄'];
        var info = GLOBAL.getMotorInfo(order);
        var status = GLOBAL.getMotorStatus(order);
        this.motorName.string = LangLocal.word31 + '：' + info.name;
        this.motorDesc.string = LangLocal.word32 + '：' + TRANS_INFO[info.type];
        this.motorOdds.string = LangLocal.word8 + ' x' + status.rate.toFixed(2);
        this.motorState.progress = status.status;
        this.motorArma.armatureName = roles[order];
        this.drawEnergy(this.energys[order]);
    },

    drawEnergy(data) {
        var lens = [data.gonglv, data.zouxian, data.bizhen, data.dongli, data.zhidong];
        this.motorEnergy.clear();
        for(var i = 0; i < 5; i++) {
            var d = Math.PI * 2 / 5 * i + 0.28;
            var x = lens[i] * Math.cos(d) * 6;
            var y = lens[i] * Math.sin(d) * 6;
            if(i == 0) this.motorEnergy.moveTo(x, y);
            else this.motorEnergy.lineTo(x, y);
        }
        this.motorEnergy.close();
        this.motorEnergy.fill();
    },
});
